import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path";
import {createSvgIconsPlugin} from "vite-plugin-svg-icons";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import {ElementPlusResolver} from "unplugin-vue-components/resolvers";

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        // 自动导入模块
        AutoImport({
            // ElementPlusResolver: 一个自动导入的解析器
            resolvers: [ElementPlusResolver()],
        }),
        // 自动导入组件
        Components({
            resolvers: [ElementPlusResolver()],
        }),
        // 在 Vite 中使用 SVG 图标
        createSvgIconsPlugin({
            // 指定需要缓存的图标文件夹
            iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
            // 指定symbolId格式
            symbolId: "icon-[dir]-[name]",
        }),
    ],
    //  用于配置模块解析的选项
    resolve: {
        // https://cn.vitejs.dev/config/#resolve-alias
        alias: {
            // 设置路径
            "~": path.resolve(__dirname, "./"),
            // 设置别名
            "@": path.resolve(__dirname, "./src"),
        },
        // https://cn.vitejs.dev/config/#resolve-extensions
        extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
    },
    server: {
        // 是否在启动服务器时自动打开浏览器
        open: true,
        proxy: {
            "/api": {
                target: "http://localhost:9001",
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, ""),
            },
        },
    }
})